  class Ability
  include CanCan::Ability
  
  def initialize(user)
      user ||= User.new(:priority =>"0") # guest user (not logged in)
        if user.priority? >= 3
          can :manage, :all
        elsif user.priority? >= 2 #Profesor y administrador
          can :manage, Post
          can [:read,:create], Comment
          can :destroy, Comment do |comment| comment.post.user.id
            user_id==comment.post.user.id
          end
          can :manage, User
        elsif user.priority? >= 1 #Student
          can [:update,:show], User ,:id => user.id
          can [:create,:read], Comment
        else #Guest
          can :read, Post
          can :read, Comment
          can :create, User
        end
  end
    # Define abilities for the passed in user here. For example:
    #
    #   user ||= User.new # guest user (not logged in)
    #   if user.admin?
    #     can :manage, :all
    #   else
    #     can :read, :all
    #   end
    #
    # The first argument to `can` is the action you are giving the user permission to do.
    # If you pass :manage it will apply to every action. Other common actions here are
    # :read, :create, :update and :destroy.
    #
    # The second argument is the resource the user can perform the action on. If you pass
    # :all it will apply to every resource. Otherwise pass a Ruby class of the resource.
    #
    # The third argument is an optional hash of conditions to further filter the objects.
    # For example, here the user can only update published articles.
    #
    #   can :update, Article, :published => true
    #
    # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities

end
